package environment;

import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

public class DPBF {
	private int environmentNumber;
	private Id id;
	int age;
	private Genotype genotype;
	
	//Constructor
	public DPBF(Genotype genotype, int environmentNumber,Id parantId){
		this.id = parantId.extendId();
		this.environmentNumber = environmentNumber;
		this.age = 0;
	}
	
	/**
	 * 1. Randomize the amount of cell to swap<br>
	 * 2. Randomly choose which cells to swap.<br>
	 * 3. Create two new DPBF with the crossed over genotype<br>
	 * @param first a 
	 * @param second
	 * @return a new array of size two containing two new DPBF with genotype combined of a crossOver from the two inputs
	 */
	public static DPBF[] crossover(DPBF first, DPBF second) {
		DPBF[] ans = new DPBF[2];
		// choose a random number from 0 to 6 (including 6);
		int amountOfCrossovers = Genotype.random.nextInt(7);
		Set<Integer> indexs = new TreeSet<Integer>();// a container from the
														// index numbers
		while (indexs.size() < amountOfCrossovers) {
			indexs.add(Genotype.random.nextInt(7));
		}

		int temp;
		for (Integer index : indexs) {
			temp = first.getGenotypeAt(index);
			first.genotype.set(index, second.getGenotypeAt(index));
			second.genotype.set(index, temp);
		}

		return ans;
	}
	
	private int getGenotypeAt(Integer index) {
		return this.genotype.indexAt(index);
	}

	//add mutation
	public void mutation(){
		this.genotype.mutate();
	}

	public Id getId() {
		return this.id;
	}
	
	
}
